<template>
	<view class="content">
		<view class="uni-list">
			<view class="uni-list-cell" hover-class="uni-list-cell-hover" v-for="(item,index) in news_list" :key="index" @tap="articleDetail" :data-newsid="item.id" :data-index="index">
				<view class="uni-media-list">
					<image class="uni-media-list-logo" :src="jpress_host + item.thumbnail"></image>
					<view class="uni-media-list-body">
						<view class="uni-media-list-text-top">{{item.title}}</view>
						<view class="uni-media-list-text-bottom uni-ellipsis">{{item.created}}</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import jpress from "@/common/jpress.js"
	export default {
		data() {
			return {
				news_list : [],
				jpress_host:''
			};
		},
		onLoad:function(){
			this.jpress_host = jpress.config.host;
			uni.showLoading({
				title:"加载中...."
			})
			this.loadArticles();
			uni.hideLoading();
		},
		methods: {
			loadArticles(){
				jpress.getArticlePage({
						page: 1,
					})
					.then(data => {
						console.log(data);
						this.news_list=data.page.list
					});
			},
			articleDetail(e) {
				uni.setStorageSync('article',this.news_list[e.currentTarget.dataset.index]);
				var newsid = e.currentTarget.dataset.newsid;
				uni.navigateTo({
					url: '../../news-base/news-info?newsid='+newsid
				});
			}
		}
	}
</script>

<style>
.uni-media-list-body{height: auto;}
.uni-media-list-text-top{line-height:1.6em;}
</style>
